<?php

namespace App\Http\Controllers\Admin;

use App\Model\Admin;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Hash;

class AdminController extends Controller
{
    public function login(){
        return view('admin.admin.login');
    }
    public function loginRes(Request $request){
        $username = $request->input('username');
        $password = $request->input('password');
        $user = new Admin();
        $userInfo = $user->where('username',$username)->first();
        if($userInfo){
            if(md5($password) == $userInfo->password){
                session(['admin'=>$username]);
                session()->save();
                return redirect('/admin')->with("success","登录成功");
            }else{
                return back()->with("errors","用户名或密码错误");
            }
        }else{
            return back()->with("errors","用户名或密码错误");
        }
    }
}
